#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    extern char** environ;
    putenv("PRIVATE_ENV=66666");
    pid_t id = fork();
    if(id == 0)
    {
      //  char* const myargv[]={
      //      "ls",
      //      "-a",
      //      "-l",
      //      NULL
      //  };
        //child
        printf("befor: I am a process,pid: %d, ppid: %d\n",getpid(),getppid());
        //sleep(5);
        //这类方法的标准写法
       // execl("/usr/bin/ls","ls","-a","-l",NULL);
       // execlp("ls","ls","-a","-l",NULL);
       // execl("/usr/bin/top","top",NULL);
       
       // execv("/usr/bin/ls",myargv);
       //execvp("ls",myargv); 
        //execl("./otherExe","otherExe",NULL);
       //execl("/usr/bin/bash","bash","test.sh",NULL);
        char* const myargv[]={
            "otherExe",
            "-a",
            "-l",
            NULL
        };
        
        char* const myenv[]={
            "MYVAL=11111",
            "MYPATH=/usr/bin/XXX",
            NULL
        };

       // execv("./otherExe",myargv);
        //execle("./otherExe","otherExe","-a","-l","-w",NULL,environ);
        execle("./otherExe","otherExe","-a","-l","-w",NULL,myenv);
        
        printf("after: I am a process,pid: %d, ppid: %d\n",getpid(),getppid());
       exit(1);
    }
    //father
    pid_t ret = waitpid(id,NULL,0);
    if(ret > 0) 
        printf("wait success,father pid: %d, ret id: %d\n",getpid(),ret);

    //sleep(5);
    return 0; 
}
